﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"
#include "GnufSliderControl.h"

namespace gnuf {
    class QtSlider;
    class QtItem;

    class GNUF_BASE_EXPORT Slider final
        : public ItemWith<QtSlider>
        , public SliderControlAdpatation
    {
        CANNOT_COPY_OR_ASSIGN(Slider);
        GNUF_WATCHABLE_OBJECT(Slider)
    public:
        static const EItemType Type;
        explicit Slider(Item*, SliderRange& sr = SliderRange(0, 100, 0), const std::wstring unit = L"");
        virtual ~Slider();

        // read and set sliderRange 
        const std::pair<int, int> range() const { return { m_Range.minimum, m_Range.maximum }; }
        void setRange(const std::pair<int, int>& sr, bool notifyIfChanged = false);

        // read and set unit for slider value
        const std::wstring& unitText() const { return m_Unit; }
        void setUnit(const std::wstring& unit);

        // read and set value for slider 
        void setValue(int, bool notifyIfChanged = false);
        int value() const;

        virtual void onConnectedWith(InputControl*) override;
    protected:
        // Inherits from ItemWith...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onPostVisibilityChanged() override;
        virtual void onPostAbilityChanged() override;
        virtual void onPostAppearanceSettingChanged() override;

        // Inherits from TextControlAdpatation...
        virtual void onValueChanged(const int) override;
        virtual void onRangeChanged(const std::pair<int, int>&) override;
        virtual void onAbilityChanged(bool) override;
        virtual void onCollectLocation(std::set<const gcmp::UniqueString*>&) const override;

    private:

        SliderRange m_Range;
        std::wstring m_Unit;
    };
}
